682C - Alyona and the Tree - CodeForces Solution


dfs and similar dp graphs trees *1600

Please click on ads to support us..

C++ Code:

#include<cstdio>
const int N=1e5+1;
bool f[N];
int i,j,k,n,t,a[N],sz[N];
int fa[N],en[N],nxt[N],w[N];
void dfs(int u,long long d)
{
if(d>a[u])return;
if(d<0)d=0;
for(int i=fa[u];i;i=nxt[i])
dfs(en[i],d+w[i]);
f[u]=1;
}
int main()
{
scanf("%d",&n);
for(i=1;i<=n;++i)
scanf("%d",a+i);
for(i=2;i<=n;w[i++]=t)
{
scanf("%d%d",&j,&t);
en[i]=i,nxt[i]=fa[j],fa[j]=i;
}
for(dfs(i=1,j=0);i<=n;++i)j+=f[i];
printf("%d",n-j);
}


Comments

Submit
0 Comments
More Questions

Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array